package com.chookss.mine.personal;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.base.StaticClass;
import com.chookss.home.entity.LogEntity;
import com.chookss.home.logContacts.LogDetailActivity;
import com.chookss.home.logContacts.LogImagsAdapter;
import com.chookss.home.publish.PublishLogsActivity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.GridSpacingItemDecoration;
import com.chookss.tools.MyEvent;
import com.chookss.tools.MyToast;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.PermissionSpUtils;
import com.chookss.tools.SignUtils2;
import com.chookss.tools.Utils;
import com.chookss.tools.XJson;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.OkGoUtil;
import com.chookss.tools.okgoconfig.callback.JsonCallback;
import com.chookss.tools.okgoconfig.callback.ObserverCallback;
import com.chookss.tools.okgoconfig.model.LzyResponse;
import com.chookss.view.BottomListsDialog;
import com.chookss.view.CircleImageView;
import com.chookss.view.RecycleViewDivider;
import com.chookss.view.SelectDialogListener;
import com.google.gson.reflect.TypeToken;
import com.johnrambo.ktea.ktExtends.ShareUtils;
import com.lvgroup.hospital.base.BaseAct;
import com.lzy.okgo.model.Response;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;

public class MyLogActivity extends BaseAct {


    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.rvView)
    RecyclerView recyclerView;
    @BindView(R.id.srlView)
    SmartRefreshLayout smrRf;
    @BindView(R.id.ivNone)
    ImageView ivNone;
    @BindView(R.id.tvNone)
    TextView tvNone;
    @BindView(R.id.tvNone2)
    TextView tvNone2;
    @BindView(R.id.llNone)
    LinearLayout llNone;
    @BindView(R.id.llBg)
    LinearLayout llBg;
    private String employeeCode;
    private int currentPage = 1;
    private boolean isEnd = false;//是否到底
    private int type = 1;
    private BottomListsDialog bottomListsDialog = null;
    private LogListAdapter adapter;
    private List<LogEntity> list = new ArrayList<>();
    private List<LogEntity> cacheList = new ArrayList<>();
    private List<String> dialogList = new ArrayList<>();
    private List<String> dialogList2 = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        setContentView(R.layout.common_srlview_center);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState();
        NavigationTools.saveUseRecord(this, "1", "02");
        commonTitleTxt.setText("我的日志");
        employeeCode = getIntent().getStringExtra("employeeCode");
        smrRf.setPadding(0, Utils.dip2px(this, 12), 0, 0);
        ivNone.setBackgroundResource(R.drawable.icon_default_no_common);
        tvNone.setText("暂无日志");
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager
                .VERTICAL, false));
        recyclerView.addItemDecoration(new RecycleViewDivider(
                this, LinearLayoutManager.HORIZONTAL, Utils.dip2px(this, 0.5f), getResources().getColor(R.color.line_gray)
        ));
        recyclerView.setPadding(Utils.dip2px(this, 12), 0, Utils.dip2px(this, 12), 0);
        recyclerView.setBackgroundColor(this.getResources()
                .getColor(R.color.white));
        adapter = new LogListAdapter(R.layout.item_look_log, this, list);
        recyclerView.setAdapter(adapter);
        ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        smrRf.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                if (isEnd) {//has next page
                    MyToast.show("没有更多数据了");
                    loadEnd();
                } else {
                    currentPage++;
                    getData();
                }
            }
        });
        smrRf.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                getCache();
                currentPage = 1;
                isEnd = false;
                getData();
            }
        });
        dialogList.add("修改");
        dialogList.add("删除");
        dialogList2.add("删除");
        dialogList2.add("取消");
        smrRf.autoRefresh();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        getCache();
    }

    private void getCache() {
        cacheList.clear();
        cacheList.addAll(XJson.getLogCache(this, LogEntity.class));
    }

    private void getData() {
        Map<String, String> allmap = new HashMap<>();
        allmap.put("type", "1");
        allmap.put("reportType", "");
        allmap.put("employeeCode", employeeCode);
        allmap.put("pageNum", currentPage + "");
        allmap.put("pageSize", "20");
        MyHttpRequest.getDefault().postRequest(new TypeToken<LzyResponse<List<LogEntity>>>() {
        }.getType(), null, Urls.getReportList, SignUtils2.makeSignStr(allmap), false, new ObserverCallback<List<LogEntity>>() {
            @Override
            public void onSuccess(List<LogEntity> data) {
                if (currentPage == 1) {
                    list.clear();
                    adapter.notifyDataSetChanged();
                }
                if (smrRf == null || llNone == null) {
                    return;
                }
                int oldIndex = list.size();
                if (data != null && data.size() > 0) {
                    if (currentPage == 1 && cacheList.size() > 0) {
                        for (int i = 0; i < cacheList.size(); i++) {
                            if (data.get(0).getTitle().equals(cacheList.get(i).getTitle()) && data.get(0).getContent().equals(cacheList.get(i).getContent())) {
                                XJson.setLogCache(MyLogActivity.this, 1, cacheList.get(i));
                                cacheList.remove(i);
                                if (i < cacheList.size()) {
                                    i--;
                                }
                            }
                        }
                        list.addAll(cacheList);
                    }
                    list.addAll(data);
                    adapter.notifyItemRangeChanged(oldIndex, data.size());
                    smrRf.setVisibility(View.VISIBLE);
                    llNone.setVisibility(View.GONE);
                } else {
                    isEnd = true;
                    if (list.size() == 0) {
                        smrRf.setVisibility(View.GONE);
                        llNone.setVisibility(View.VISIBLE);
                    }

                }
                loadEnd();
            }

            @Override
            public void onError(String errorMsg) {
                loadEnd();
                MyToast.show(Utils.onErrorTips(errorMsg));
            }
        });
    }

    private void deleteMyReport(LogEntity logEntity, int position) {
        Map<String, String> map = new HashMap<>();
        map.put("reportCode", logEntity.getReportCode());
        map.put("reportType", logEntity.getReportType());
        MyHttpRequest.postRequest(Urls.deleteMyReport, this, SignUtils2.makeSignStr(map), new JsonCallback<String>() {
            @Override
            public void onSuccess(Response<String> response) {
                try {
                    JSONObject jsonObject = new JSONObject(response.body().toString());
                    if ("200".equals(jsonObject.getString("code"))) {
                        MyToast.show("删除成功");
                        if (recyclerView == null || llNone == null) {
                            return;
                        }
                        list.remove(position);
                        adapter.notifyItemRemoved(position);
                        adapter.notifyItemRangeChanged(position, list.size() - position);
                        HashMap<String, String> map = new HashMap<>();
                        map.put("reportCode", logEntity.getReportCode());
                        map.put("deleteLog", "true");
                        EventBus.getDefault().post(new MyEvent(map));
                        if (list.size() == 0) {
                            recyclerView.setVisibility(View.GONE);
                            llNone.setVisibility(View.VISIBLE);
                        }
                    } else {
                        if (jsonObject.getString("code").startsWith("400")) {
                            OkGoUtil.onErrorIntent(jsonObject.getString("code"),jsonObject.getString("msg"));
                        }else{
                            MyToast.show(jsonObject.getString("msg"));
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    class LogListAdapter extends BaseQuickAdapter<LogEntity, BaseViewHolderEx> {
        private Context context;
        private GridSpacingItemDecoration gridSpacingItemDecoration;

        public LogListAdapter(int layoutResId, Context context, @Nullable List<LogEntity> data) {
            super(layoutResId, data);
            this.context = context;
            gridSpacingItemDecoration = new GridSpacingItemDecoration(4, Utils.dip2px(context, 8), false);

        }

        @Override
        protected void convert(BaseViewHolderEx helper, LogEntity item) {
            CircleImageView ivHead = helper.getView(R.id.ivHead);
            TextView tvName = helper.getView(R.id.tvName);
            TextView tvTime = helper.getView(R.id.tvTime);
            RelativeLayout rlMore = helper.getView(R.id.rlMore);
            TextView tv1 = helper.getView(R.id.tv1);
            TextView tv2 = helper.getView(R.id.tv2);
            TextView tv3 = helper.getView(R.id.tv3);
            TextView tv4 = helper.getView(R.id.tv4);
            TextView tv1Init = helper.getView(R.id.tv1Init);
            TextView tv2Init = helper.getView(R.id.tv2Init);
            TextView tv3Init = helper.getView(R.id.tv3Init);
            TextView tv4Init = helper.getView(R.id.tv4Init);
            LinearLayout ll3 = helper.getView(R.id.ll4);
            LinearLayout ll4 = helper.getView(R.id.ll4);
            LinearLayout llContent = helper.getView(R.id.llContent);
            RecyclerView imgRv = helper.getView(R.id.imgRv);
            LinearLayout llRead = helper.getView(R.id.llRead);
            TextView tvRead = helper.getView(R.id.tvRead);
            if ("0".equals(type)) {
                rlMore.setVisibility(View.INVISIBLE);
            } else {
                rlMore.setVisibility(View.VISIBLE);
            }
            LogImagsAdapter imagsAdapter = null;
            List<String> picList = new ArrayList<>();
            if (item.getCacheStatus() == 1) {
                if (item.getPictureList().size() > 0 || item.getVideoPictureList().size() > 0) {
                    imgRv.setVisibility(View.VISIBLE);
                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgRv.getLayoutParams();
                    params.width = Utils.getScreenWidthPixel(MyLogActivity.this) - Utils.dip2px(MyLogActivity.this, 74);
                    params.height = (Utils.getScreenWidthPixel(MyLogActivity.this) - Utils.dip2px(MyLogActivity.this, 98)) / 4;
                    imgRv.setLayoutParams(params);
                    GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context, 4);
                    imgRv.setLayoutManager(gridLayoutManager1);
                    if (imgRv.getItemDecorationCount() == 0) {
                        imgRv.addItemDecoration(gridSpacingItemDecoration);
                    }
                } else {
                    imgRv.setVisibility(View.GONE);
                }
                picList.clear();
                if (item.getPictureList().size() > 0) {
                    LogImagsAdapter adapter = null;

                    if (item.getPictureList().size() >= 4) {
                        picList.addAll(item.getPictureList().subList(0, 4));
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, -1, item, helper.getItemPosition());
                    } else {
                        picList.addAll(item.getPictureList());
                        if (item.getVideoPictureList().size() > 0) {
                            if (item.getVideoPictureList().size() >= (4 - item.getPictureList().size())) {
                                picList.addAll(item.getVideoPictureList().subList(0, 4 - item.getPictureList().size()));
                            } else {
                                picList.addAll(item.getVideoPictureList());
                            }
                        }
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, item.getPictureList().size(), item, helper.getItemPosition());
                    }
                    imgRv.setAdapter(adapter);
                } else {
                    if (item.getVideoPictureList().size() > 0) {
                        LogImagsAdapter adapter = null;
                        if (item.getVideoPictureList().size() >= 4) {
                            picList.addAll(item.getVideoPictureList().subList(0, 4));
                        } else {
                            picList.addAll(item.getVideoPictureList());
                        }
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, 0, item, helper.getItemPosition());
                        imgRv.setAdapter(adapter);
                    }
                }
            } else {
                //未上传的缓存数据
                List<String> picCacheList = new ArrayList<>();
                List<String> videoCacheList = new ArrayList<>();
                picCacheList.clear();
                videoCacheList.clear();
                for (int i = 0; i < item.getVideoBeanlist().size(); i++) {
                    if ("0".equals(item.getVideoBeanlist().get(i).getType())) {
                        picCacheList.add(item.getVideoBeanlist().get(i).getUrl());
                    } else if ("1".equals(item.getVideoBeanlist().get(i).getType())) {
                        videoCacheList.add(item.getVideoBeanlist().get(i).getUrl());
                    }
                }
                if (item.getVideoBeanlist().size() > 0) {
                    imgRv.setVisibility(View.VISIBLE);
                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgRv.getLayoutParams();
                    params.width = Utils.getScreenWidthPixel(MyLogActivity.this) - Utils.dip2px(MyLogActivity.this, 74);
                    params.height = (Utils.getScreenWidthPixel(MyLogActivity.this) - Utils.dip2px(MyLogActivity.this, 98)) / 4;
                    imgRv.setLayoutParams(params);
                    GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context, 4);
                    imgRv.setLayoutManager(gridLayoutManager1);
                    if (imgRv.getItemDecorationCount() == 0) {
                        imgRv.addItemDecoration(gridSpacingItemDecoration);
                    }
                } else {
                    imgRv.setVisibility(View.GONE);
                }
                picList.clear();
                if (picCacheList.size() > 0) {
                    LogImagsAdapter adapter = null;
                    if (picCacheList.size() >= 4) {
                        picList.addAll(picCacheList.subList(0, 4));
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, -1, item, helper.getItemPosition());
                    } else {
                        picList.addAll(picCacheList);
                        if (videoCacheList.size() > 0) {
                            if (videoCacheList.size() >= (4 - picCacheList.size())) {
                                picList.addAll(videoCacheList.subList(0, 4 - picCacheList.size()));
                            } else {
                                picList.addAll(videoCacheList);
                            }
                        }
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, picCacheList.size(), item, helper.getItemPosition());
                    }
                    imgRv.setAdapter(adapter);
                } else {
                    if (videoCacheList.size() > 0) {
                        LogImagsAdapter adapter = null;
                        if (videoCacheList.size() >= 4) {
                            picList.addAll(videoCacheList.subList(0, 4));
                        } else {
                            picList.addAll(videoCacheList);
                        }
                        adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList, 0, item, helper.getItemPosition());
                        imgRv.setAdapter(adapter);
                    }
                }
            }

            if (item.getPlayListPage() == null) {
                //用来处理上传失败缓存数据的 处理
                llRead.setVisibility(View.GONE);
//                rlMore.setVisibility(View.INVISIBLE);
                rlMore.setVisibility(View.VISIBLE);
            } else {
                rlMore.setVisibility(View.VISIBLE);
                if (item.getPlayListPage().getList().size() > 0) {
                    llRead.setVisibility(View.VISIBLE);
                    String names = "";
                    for (int i = 0; i < item.getPlayListPage().getList().size(); i++) {
                        if (i < 3) {
                            if (Utils.isNull(names)) {
                                names = names + "" + item.getPlayListPage().getList().get(i).getPlayEmployeeName();
                            } else {
                                names = names + "、" + item.getPlayListPage().getList().get(i).getPlayEmployeeName();
                            }
                        }
                    }
                    if (Utils.changeNumber(item.getPlayListPage().getTotal()) > 3) {
                        tvRead.setText(names + "等" + item.getPlayListPage().getTotal() + "人浏览过");
                    } else {
                        tvRead.setText(names + item.getPlayListPage().getTotal() + "人浏览过");
                    }
                } else {
                    llRead.setVisibility(View.GONE);
                }
            }
            GlideUtils.loadAvatar(MyLogActivity.this, item.getHeadPhotoThumbUrl(), ivHead);
            tvTime.setText(Utils.getAccurateDate(item.getCreateTime()));
            int sort = Utils.changeNumber(item.getSort());
            if (sort == 0) {
                sort = 1;
            }
            LinearLayout.LayoutParams tv1Params = (LinearLayout.LayoutParams) tv1Init.getLayoutParams();
            LinearLayout.LayoutParams tv2Params = (LinearLayout.LayoutParams) tv2Init.getLayoutParams();
            if ("0".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("今日完成工作：");
                tv2Init.setText("未完成工作：");
                tv3Init.setText("需协调工作：");
                tv4Init.setText("明日工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else if ("1".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("本周完成工作：");
                tv2Init.setText("本周工作总结：");
                tv3Init.setText("需协调与帮助：");
                tv4Init.setText("下周工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else if ("2".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(MyLogActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("本月工作内容：");
                tv2Init.setText("本月工作总结：");
                tv3Init.setText("需帮助与支持：");
                tv4Init.setText("下月工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()));
                ll3.setVisibility(View.GONE);
                ll4.setVisibility(View.GONE);
                tv1Params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                tv1Params.gravity = Gravity.LEFT;
                tv2Params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                tv2Params.gravity = Gravity.LEFT;
                tv1Init.setText("日志标题：");
                tv2Init.setText("日志内容：");
                tv1.setText(item.getTitle());
                tv2.setText(item.getContent());
            }
            tv1Init.setLayoutParams(tv1Params);
            tv2Init.setLayoutParams(tv2Params);
            rlMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (item.getPlayListPage() == null) {
                        //用来处理上传失败缓存数据的 处理
                        bottomListsDialog = new BottomListsDialog(MyLogActivity.this, dialogList2, new SelectDialogListener() {
                            @Override
                            public void onCancel() {

                            }

                            @Override
                            public void onListItemClick(int position, List<String> list2) {
                                if (position == 0) {
                                    MyToast.show("删除成功");
                                    XJson.setLogCache(MyLogActivity.this, 1, item);
                                    list.remove(helper.getItemPosition());
                                    adapter.notifyItemRemoved(helper.getItemPosition());
                                    adapter.notifyItemRangeChanged(helper.getItemPosition(), list.size() - helper.getItemPosition());
                                }
                                bottomListsDialog.dismiss();
                            }
                        });
                    } else {
                        bottomListsDialog = new BottomListsDialog(MyLogActivity.this, dialogList, new SelectDialogListener() {
                            @Override
                            public void onCancel() {

                            }

                            @Override
                            public void onListItemClick(int position, List<String> list) {
                                if (position == 0) {
                                    if (PermissionSpUtils.getBoolean(MyLogActivity.this,"12",false)) {
                                        Intent intent = new Intent(MyLogActivity.this, PublishLogsActivity.class);
                                        intent.putExtra("data", item);
                                        intent.putExtra("modify", true);
                                        startActivity(intent);
                                    } else {
                                        MyToast.show("管理员已关闭日志发布功能");
                                    }
                                } else if (position == 1) {
                                    deleteMyReport(item, helper.getItemPosition());
                                }
                                bottomListsDialog.dismiss();
                            }
                        });
                    }

                    bottomListsDialog.show();
                }
            });
            helper.getItemView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (item.getPlayListPage() != null) {
                        //用来处理上传失败缓存数据的 处理
                        readData(item, helper.getItemPosition());
                    }
                    Intent intent = new Intent(MyLogActivity.this, LogDetailActivity.class);
                    intent.putExtra("data", item);
                    intent.putExtra("position", helper.getItemPosition());
                    startActivity(intent);
                }
            });
        }

    }

    private void readData(LogEntity logEntity, int position) {
        if (logEntity.getCacheStatus() != 1) {
            return;
        }
        Map<String, String> allmap = new HashMap<>();
        allmap.put("reportCode", logEntity.getReportCode());
        allmap.put("reportType", logEntity.getReportType());
        allmap.put("reportEmployeeCode", logEntity.getEmployeeCode());
        MyHttpRequest.postRequest(Urls.getReportById, this, SignUtils2.makeSignStr(allmap), new JsonCallback<String>() {
            @Override
            public void onSuccess(Response<String> response) {
                try {
                    JSONObject jsonObject = new JSONObject(response.body().toString());
                    if (jsonObject.getString("code").equals("200")) {
                        JSONArray jsonArray = jsonObject.getJSONArray("data");
                        list.get(position).getPlayListPage().getList().clear();
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                            LogEntity.PlayListPageBean.ListBean listBean = new LogEntity.PlayListPageBean.ListBean();
                            listBean.setPlayEmployeeName(jsonObject1.getString("playEmployeeName"));
                            list.get(position).getPlayListPage().getList().add(listBean);
                        }
                        list.get(position).getPlayListPage().setTotal(jsonObject.getString("total"));
                        adapter.notifyItemChanged(position);
                    }else{
                        if (jsonObject.getString("code").startsWith("400")) {
                            OkGoUtil.onErrorIntent(jsonObject.getString("code"),jsonObject.getString("msg"));
                        }else{
                            MyToast.show(jsonObject.getString("msg"));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(MyEvent messageEvent) {
        //事件订阅者处理事件
        if (messageEvent.getHashMap() != null) {
            Map<String, String> map = messageEvent.getHashMap();
            if (map.containsKey("Log_Read")) {
                int index = Utils.changeNumber(map.get("Log_Read"));
                readData(list.get(index), index);
            } else if (map.containsKey("Log_Cache_Error_Position")) {
                int position = Utils.changeNumber(map.get("Log_Cache_Error_Position"));
                list.get(position).setCacheStatus(0);
            }
        } else {
            String msg = messageEvent.getMessage();
            if ("RefreshLogFragment".equals(msg)) {
                //刷新最近列表
                smrRf.autoRefresh();
            }
        }
    }

    @OnClick(R.id.common_title_back)
    public void onClick() {
        finish();
    }

    private void loadEnd() {
        if (null != smrRf && smrRf.getState() == RefreshState.Refreshing)
            smrRf.finishRefresh(true);
        if (null != smrRf && smrRf.getState() == RefreshState.Loading)
            smrRf.finishLoadMore(true);
    }


}
